package com.hcw.library.enumtype;


import com.hcw.library.common.Result;

public enum ResultEnum implements IResultEnum {

    //成功
    SUCCESS("成功", "200"),
    //失败
    FAIL("失败", "100002"),
    //数据库查询不到数据
    STAFFISEXISTS("该工号已存在", "100003"),

    FAILDELETED("删除失败", "100004");

    private String name;
    private String value;

    ResultEnum(String name, String value) {
        this.name = name;
        this.value = value;
    }


    public static String getName(String value) {
        for (ResultEnum c : ResultEnum.values()) {
            if (c.getValue().equals(value)) {
                return c.name;
            }
        }
        return null;
    }

    @Override
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    /**
     * 错误返回
     *
     * @param result
     * @param resultEnum
     * @return
     */
    public static void error(ResultEnum resultEnum, Result result) {
        result.setSuccess(false);
        result.setCode(resultEnum.getValue());
        result.setMessage(resultEnum.getName());
    }
}
